/**
 * Created by huotaol on 2017/5/3.
 */
import * as types from "../../constant/ActionType";
import * as CarFilterConfig from "../../config/CarFilter";

/*keyword 和 brand/series互斥*/
export const initFilterParam = {
    begin: 0,
    max: 20,
    total: 0,
    brand: '',
    series: '',
    keyword: '',
    origin: CarFilterConfig.ORIGIN[0].type,
    kind: [],
    gearbox: CarFilterConfig.GEARBOX[0].type,
    emission: [],
    price: {from: 0, to: '∞'},
    meter: {from: 0, to: '∞'},
    year: {from: 0, to: '∞'},
    displacement: {from: 0, to: '∞'},
    shopID: '',
    sold: true,
    orderType: CarFilterConfig.ODER_TYPE[0].type,
    orderBy: CarFilterConfig.ORDER_BY[0].name,
};

function buyCarFilter(state = Object.assign({}, initFilterParam), action) {
    switch (action.type) {
        case types.BUY_CAR_FILTER:
            return Object.assign({}, state, {
                begin: action.begin,
                total: action.total,
                brand: action.brand,
                series: action.series,
                keyword: action.keyword,
                origin: action.origin,
                kind: action.kind,
                gearbox: action.gearbox,
                emission: action.emission,
                price: {from: action.price.from, to: action.price.to},
                meter: {from: action.meter.from, to: action.meter.to},
                year: {from: action.year.from, to: action.year.to},
                displacement: {from: action.displacement.from, to: action.displacement.to},
                shopID: action.shopID,
                sold: action.sold,
                orderType: action.orderType,
                orderBy: action.orderBy,
            });
        default:
            return state;
    }
}

const initBrand = {
    data: {'热': []},
};

function brand(state = {...initBrand}, action) {
    switch (action.type) {
        case types.BRAND_RECEIVE:
            return Object.assign({}, state, {
                data: action.data,
            });
        default:
            return state;
    }
}

const initSeries = {
    data: []
};
function series(state = Object.assign({}, initSeries), action) {
    switch (action.type) {
        case types.SERIES_RECEIVE:
            return Object.assign({}, state, {
                data: action.data,
            });
        default:
            return state;
    }
}

export default {buyCarFilter, brand, series,};